package com.mvc4g.example.client.customer.views;

import com.google.gwt.user.client.ui.TextBox;
import com.mvc4g.client.Event;
import com.mvc4g.example.client.customer.CustomerBean;

public class CreateCustomerView extends AbstractCustomerView {

	private TextBox lastName = null;
	private TextBox firstName = null;

	protected void finishCreation() {
		lastName = new TextBox();
		firstName = new TextBox();
		grid.setWidget(0, 1, lastName);
		grid.setWidget(1, 1, firstName);
	}

	public void init(CustomerBean customer) {
		if(customer != null){
		lastName.setText(customer.getLastName());
		firstName.setText(customer.getFirstName());
		}
		else{
			lastName.setText(EMPTY_STRING);
			firstName.setText(EMPTY_STRING);
		}
		
	}

	protected String getButtonText() {
		return "Create";
	}

	protected void buttonAction() {
		CustomerBean customer = new CustomerBean();
		customer.setLastName(lastName.getText());
		customer.setFirstName(firstName.getText());
		controller.handleEvent(new Event(CREATE_CUSTOMER, customer));
	}

}
